﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace ICodeShare.UI.Converters
{
    /// <summary>
    /// 
    /// </summary>
    [ValueConversion(typeof(byte), typeof(byte))]
    [ValueConversion(typeof(short), typeof(short))]
    [ValueConversion(typeof(int), typeof(int))]
    [ValueConversion(typeof(long), typeof(long))]
    [ValueConversion(typeof(float), typeof(float))]
    [ValueConversion(typeof(double), typeof(double))]
    [ValueConversion(typeof(decimal), typeof(decimal))]
    public sealed class NumericToNegativeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is byte)
            {
                return (byte)((byte)value * -1);
            }
            if (value is short)
            {
                return (short)(Math.Abs((short)value) * -1);
            }
            if (value is int)
            {
                return Math.Abs((int)value) * -1;
            }
            if (value is long)
            {
                return Math.Abs((long)value) * -1L;
            }
            if (value is float)
            {
                return Math.Abs((float)value) * -1f;
            }
            if (value is double)
            {
                return Math.Abs((double)value) * -1d;
            }
            if (value is decimal)
            {
                return Math.Abs((decimal)value) * -1m;
            }
            return DependencyProperty.UnsetValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Convert(value, targetType, parameter, culture);
        }
    }
}
